/**
 * @(#)ProcessIconTag.java Dec 28, 2009
 *   
 * Copyright  (c) 2009-2010 Wilmar IT Service,  Inc.   
 * All  rights  reserved.   
 * TODO
 */

package com.wilmar.process.web.taglibs;

import javax.servlet.jsp.JspWriter;

import com.wilmar.process.core.ProcessSystemDeclareKeys;
import com.wilmar.process.enumerate.EnumTagLibResource;

/**
 * @author MaKuBEX Email:makubexnet@gmail.com
 * @version 1.0.0
 */
public class ProcessIconTag extends ProcessTagSupport {

	/**
	 * @serialField
	 */
	private static final long serialVersionUID = 5945751489690004021L;
	private String icon;
	private String tooltip;
	private String height;
	private String width;

	/**
	 * @see org.springframework.web.servlet.tags.RequestContextAwareTag#doStartTagInternal()
	 */
	protected int doStartTagInternal() throws Exception {
		String c_height = ProcessSystemDeclareKeys.DEFAULT_ICON_HEIGHT;
		if (this.height != null && this.height.trim().length() != 0)
			c_height = this.height;
		String c_width = ProcessSystemDeclareKeys.DEFAULT_ICON_WIDTH;
		if (this.width != null && this.width.trim().length() != 0)
			c_width = this.width;
		StringBuffer html = new StringBuffer();
		html.append("<img width=\"");
		html.append(c_width);
		html.append("\" height=\"");
		html.append(c_height);
		html.append("\" border=\"0\" src=\"");
		html.append(super.getContextPath());
		html.append(ProcessSystemDeclareKeys.PAGE_ICON_DIR);
		html.append(ProcessSystemDeclareKeys.SLASH);
		html.append(this.icon);
		html.append(ProcessSystemDeclareKeys.ICON_SUFFIX);
		html.append("\"");
		html.append("title=\"");
		if (this.tooltip != null && this.tooltip.trim().length() != 0) {
			html
					.append(super.getText(EnumTagLibResource
							.valueOf(this.tooltip)));
		} else {
			html.append(super.getText(EnumTagLibResource
					.valueOf("PROCESS_ICON_TEXT_TOOLTIP_"
							+ this.icon.toUpperCase())));
		}
		html.append("\" ");
		html.append("/>");
		JspWriter outer = this.getOut();
		outer.write(html.toString());
		return SKIP_BODY;
	}

	/**
	 * @return the icon
	 */
	public String getIcon() {
		return icon;
	}

	/**
	 * @param icon
	 *            the icon to set
	 */
	public void setIcon(String icon) {
		this.icon = icon;
	}

	/**
	 * @return the tooltip
	 */
	public String getTooltip() {
		return tooltip;
	}

	/**
	 * @param tooltip
	 *            the tooltip to set
	 */
	public void setTooltip(String tooltip) {
		this.tooltip = tooltip;
	}

	/**
	 * @return the height
	 */
	public String getHeight() {
		return height;
	}

	/**
	 * @param height
	 *            the height to set
	 */
	public void setHeight(String height) {
		this.height = height;
	}

	/**
	 * @return the width
	 */
	public String getWidth() {
		return width;
	}

	/**
	 * @param width
	 *            the width to set
	 */
	public void setWidth(String width) {
		this.width = width;
	}

}
